#include<bits/stdc++.h>
#define N 10100
#define int long long
using namespace std;
int n, k, Q, now, ans;
int a[N];
void dfs(int l, int r, int v) {
    if(l == 1 && r == n) {
        return;
	}
	if(l != 1 && a[l - 1] <= v) {
	    now++;
	    dfs(l - 1, r, v);
	}
	else if(r != n && a[r + 1] <= v) {
	    now++;
	    dfs(l, r + 1, v);
	}
	else {
	    now += k;
	    dfs(l, r, min(a[l - 1], a[r + 1]));
	}
}
signed main() {
	freopen("summer.in", "r", stdin);
    freopen("summer.out", "w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cin >> Q;
    a[0] = a[n + 1] = 1e9 + 7;
    while(Q--) {
        int x, l, r;
        cin >> x >> l >> r;
        ans = 0;
        swap(a[x], a[x + 1]);
        for(int i = l; i <= r; i++) {
            now = 0;
            dfs(i, i, a[i]);
            ans += now;
		}
		cout << ans << endl;
	}
	return 0;
}
